<?php
import('ORG.Util.Input');
import('@.ORG.FAC');
/**
 * 友情链接模型
 * Enter description here ...
 * @author Code.404
 *
 */
class FriendlinkModel extends Model{
	protected $_validate = array(
		array('link_name','require','LINK_NAME_HAS_EXISTS',MODEL::EXISTS_VAILIDATE ,'unique',1),
		array('link_url','require','LINK_URL_MUST_EXISTS',MODEL::EXISTS_VAILIDATE )
	);
	/**
	 * 新增链接
	 * Enter description here ...
	 * @param array $data
	 */
	function addLink(Array $data){
		$_data['link_name'] = FAC::F($data['link_name'] , FAC::STRING , 1 , 50);
		$_data['link_url'] = FAC::F($data['link_url'],FAC::URL);
		$_data['link_priority'] = FAC::F($data['link_priority'] , FAC::PRIORITY);
		$_data['link_style'] = $data['link_style'] == 1 ? 1 : 0;
		$_data['link_image'] = FAC::F($data['link_image']);
		
		if($this->create($_data)){
			if($this->add()){
				return true;
			}
		}
		return false;
	}
	/**
	 * 修改链接
	 * Enter description here ...
	 * @param unknown_type $data
	 */
	function modifyLink(Array $data) {
		$_data['link_name'] = FAC::F($data['link_name'] , FAC::STRING , 1 , 50);
		$_data['link_url'] = FAC::F($data['link_url'],FAC::URL);
		$_data['link_priority'] = FAC::F($data['link_priority'] , FAC::PRIORITY);
		$_data['link_style'] = $data['link_style'] == 1 ? 1 : 0;
		$_data['link_image'] = FAC::F($data['link_image']);
		
		$_map['id'] = FAC::F($data['id'] , FAC::INT);
		
		if($this->where($_map)->save($_data)){
			return true;
		}
		
		return false;
	}
}